﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SAM_Edu.control;
using System.IO;
using SAM_Edu.validate;


namespace SAM_Edu.form
{
    public partial class frmStartUp : Form
    {
        public frmStartUp()
        {
            InitializeComponent();
        }
        public frmStartUp(frmMain m1_)
        {
            InitializeComponent();
            this.mdiParent = m1_;
        }
        bool setup = false;
        private void frmStartUp_Load(object sender, EventArgs e)
        {
            
          
            axWindowsMediaPlayer1.Ctlcontrols.stop();
            axWindowsMediaPlayer1.URL = Path.GetFullPath("../../resources/SplashScreen.mp4");
            String asdasd = axWindowsMediaPlayer1.URL;
            axWindowsMediaPlayer1.Ctlcontrols.play();

            Timer _tmr = new Timer();

            _tmr.Interval = 5000;  // interval in millisecond

            _tmr.Tick += new EventHandler(tmr_Tick);


            _tmr.Start();

            //axWindowsMediaPlayer1.Ctlcontrols.stop();
            string check = Startup.checkLicense();
            if (check == "")
            {
                setup = true;
            }
            else
            {

               

                SAM_Edu.entity.License l = Startup.getLicensee();
                DateTime lastvalidationdate = Startup.validateLicense();
                string results = "true";
                if (((System.DateTime.Now.Year - lastvalidationdate.Year) * 12) + System.DateTime.Now.Month - lastvalidationdate.Month > 3)
                {
                    validateLicense vl = new validateLicense();
                    results = vl.vLicense(check);
                   
                }
                if (results == "true")
                {
                    Startup.updateLastActivationDate(check);
                    this.ParentForm.Controls["lbLicense"].Text = ("xxxx-xxxx-xxxx-" + check.Substring(12, check.Length - 12));
                    this.ParentForm.Controls["lblFooter"].Text = "SAM Teaching Material \n" + "Licensed To " + l.Name.ToString() + "\nCopyright 2014 EightyTwenty PTE LTD";
                    this.ParentForm.Controls["companylogo"].BackgroundImage = byteArrayToImage(l.Logo);
                    //mdiParent = new frmMain();
                    //mdiParent.companyLogo.Image = byteArrayToImage(l.Logo);
                    //mdiParent.companyLogo.Refresh();
                    //mdiParent.companyLogo.Update();
                }
            }

        }
        void tmr_Tick(object sender, EventArgs e)
        {

            btnSkip.Enabled = true;

        }
        private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
        {

        }


        private frmMain mdiParent;
        private void btnSkip_Click(object sender, EventArgs e)
        {
            if (setup == true)
            {
                
                this.Hide();
                frmSetupSW sw = new frmSetupSW();
                sw.MdiParent = this.MdiParent;
                sw.StartPosition = FormStartPosition.Manual;
                sw.Location = new System.Drawing.Point(10, 10);
                sw.Show();
                this.Close();

                
            }
            else
            {

                
                
                frmLogon sw = new frmLogon();
                sw.MdiParent = this.MdiParent;
                sw.StartPosition = FormStartPosition.Manual;
                sw.Location = new System.Drawing.Point(10, 10);
                sw.Show();
                this.Close();
         
                
            }
        }
        public Image byteArrayToImage(byte[] byteArrayIn)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn);
            Image returnImage = Image.FromStream(ms);
            return returnImage;
        }
        private void axWindowsMediaPlayer1_Enter_1(object sender, EventArgs e)
        {

        }

        private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
        {
            // Test the current state of the player and display a message for each state. (Fong Kin Shing)
            switch (e.newState)
            {
                case 0:    // Undefined

                    break;

                case 1:    // Stopped

                    frmLogon sw = new frmLogon();
                sw.MdiParent = this.MdiParent;
                sw.StartPosition = FormStartPosition.Manual;
                sw.Location = new System.Drawing.Point(10, 10);
                sw.Show();
                this.Close();
                   // axWindowsMediaPlayer1.URL = "";
                    break;

                case 2:    // Paused

                    break;

                case 3:    // Playing

                    break;

                case 4:    // ScanForward

                    break;

                case 5:    // ScanReverse

                    break;

                case 6:    // Buffering

                    break;

                case 7:    // Waiting

                    break;

                case 8:    // MediaEnded

                    break;

                case 9:    // Transitioning

                    break;

                case 10:   // Ready

                    break;

                case 11:   // Reconnecting

                    break;

                case 12:   // Last

                    break;

                default:
                    MessageBox.Show("Unknown State: " + e.newState.ToString());
                    break;
            }
        }



    }
}
